/*
 * 2005-11-16 lxm 创建。 
 */
package com.hd123.rumba.catalog;

import java.text.ParseException;

import net.sf.hibernate.HibernateException;

import com.hd123.rumba.exception.BusinessException;
import com.hd123.rumba.runtime.DBaseEntity;
import com.hd123.rumba.runtime.IPersistent;
import com.hd123.rumba.runtime.NamingMgr;

/**
 * @author lxm
 *
 * ICategory对应的数据交换对象
 */
public class DCategory extends DBaseEntity {

  private String catalogUuid;
  private String code;
  private String name;
  private String parentUuid;
  private String usedType;
  private String remark;

  // /////////////////////////
  // 用于 Web Service 数据交换

  /**
   * 从指定的接口对象赋值。
   * 
   * @param source
   */
  public void assignFrom(IPersistent source) {
    super.assignFrom(source);
    if (source instanceof ICategory) {
      this.catalogUuid = exportString(source, new String[] {"getCatalog", "getUuid"});
      this.code = exportString(source, "getCode");
      this.name = exportString(source, "getName");
      this.parentUuid = exportString(source, new String[] {"getParent", "getUuid"});
      this.usedType = exportString(source, "getUsedType");
      this.remark = exportString(source, "getRemark");
    }
  }

  /**
   * 将数据赋值给指定的接口对象。
   * 
   * @param source
   */
  public void assignTo(IPersistent target) throws ParseException, BusinessException,
      HibernateException {
    super.assignTo(target);
    if (target instanceof ICategory) {
      setPropValue(target, "setCatalog", DCatalog.importCatalog(this.catalogUuid));
      importString(target, "setCode", this.code);
      importString(target, "setName", this.name);
      setPropValue(target, "setParent", importCategory(this.parentUuid));
      importString(target, "setUsedType", this.usedType);
      importString(target, "setRemark", this.remark);
    }
  }
  
  /**
   * 用于导入处理，根据Uuid导入指定的Category。
   * 
   * @param uuid
   * @return
   * @throws BusinessException
   * @throws HibernateException
   */
  public static ICategory importCategory(String uuid) throws BusinessException, HibernateException {
    if (uuid == null || uuid.equals(new String("")))
      return null;
    ICategory category = ((ICatalogMgr) NamingMgr.getInstance().lookupMgr(ICatalogMgr.class))
        .getCategory(uuid);
    if (category == null)
      throw new BusinessException("系统中不存在指定的分类(uuid=" + uuid + ")。");
    return category;
  }

  // /////////////////////////
  // 属性方法

  public String getCatalogUuid() {
    return catalogUuid;
  }

  public void setCatalogUuid(String catalogUuid) {
    this.catalogUuid = catalogUuid;
  }

  public String getCode() {
    return code;
  }

  public void setCode(String code) {
    this.code = code;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getParentUuid() {
    return parentUuid;
  }

  public void setParentUuid(String parentUuid) {
    this.parentUuid = parentUuid;
  }

  public String getRemark() {
    return remark;
  }

  public void setRemark(String remark) {
    this.remark = remark;
  }

  public String getUsedType() {
    return usedType;
  }

  public void setUsedType(String usedType) {
    this.usedType = usedType;
  }
  
}
